<?php

namespace Common\Model;

/**
 * 数据采集 模型
 *
 * @author BoBo
 *        
 */
class ApplyModel extends CommModel {
	
	// 自动验证
    protected $_validate = array(array('username', '2,20', '姓名填写有误!', self::EXISTS_VALIDATE, 'length'),  array('tel', '/^(13[0-9]|15[0-9]|18[0-9]|14[0-9])[0-9]{8}/i', '手机号码格式填写有误', self::EXISTS_VALIDATE));
    
	//验证占用字段
    public function checkField($condition, $field) {
        return $this->where($condition)->getField($field);
    }
	
    // 用户贷款申请
    public function addPost($data) {
        $return = returnMsg();
        if ($this->create($data)) {
            // 判断用户名是否被占用
            $isTel = $this->checkField(array('tel' => $data['tel'], 'is_delete' => 0), "tel");
            
			if(!empty($isTel)){
            	$return['info'] = "电话号码已被占用!";
            }else {
                $return['status'] = $this->add();
                if (empty($return['status'])) {
                    $return['info'] = "提交失败,请稍后重试!";
                } else {
                    $return['info'] = "提交成功! 我们将会尽快与您取得联系！";
                }
            }
        } else {
            $return['info'] = $this->getError();
        }
        return $return;
    }
}